package middleware

import (
	"fmt"
	"gitee.com/worklz/grpc-mtls-demo/gateway/pkg/response"
	"github.com/gin-gonic/gin"
	"log"
)

// Recover 捕获panic
func Recover(ctx *gin.Context, recovered any) {
	var err error
	if rErr, ok := recovered.(error); ok {
		err = rErr
	} else {
		err = fmt.Errorf("%v", recovered)
	}
	log.Fatalf("全局panic错误捕获%T：%v", recovered, recovered)
	response.AbortFail(ctx, err.Error())
}
